package com.yanqu.road.server.manger.activity.recycle;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.ActivityItemRecycleData;
import com.yanqu.road.entity.activity.doublespring.DoubleSpringActivityConfig;
import com.yanqu.road.entity.activity.hsisland.config.HsIslandConfig;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.player.UserBagItem;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;
import com.yanqu.road.server.manger.activity.doublespring.DoubleSpringActivityMgr;
import com.yanqu.road.server.manger.activity.hsisland.HsIslandActivityMgr;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

import java.util.ArrayList;
import java.util.List;

public class HsIslandRecycleStrategy extends AbstractItemRecycleStrategy {

    @Override
    public void markNeedRecycleItem() {
        List<ActivityInfo> activityList = NormalActivityMgr.getOpenActivityInfoList(eActivityType.HsIsland.getValue());
        for (ActivityInfo activityInfo : activityList) {
            if (activityInfo != null) {
                //回收时间
                long recycleTime = activityInfo.getEndShowTime() * 1000L + 600 * 1000;
                //回收的道具ID
                HsIslandConfig config = HsIslandActivityMgr.getActivityConfig(activityInfo.getActivityId());
                if (config != null) {
                    //深海沉银
                    List<String> paramList = new ArrayList<>();
                    paramList.add(activityInfo.getActivityName());
                    paramList.add(config.HSISLAND_DONATE_REWARD);
                    ActivityItemRecycleMgr.addRecycleItemData(config.HSISLAND_DONATE_ITEM_ID, activityType, 0, recycleTime, paramList);
                    //望穿秋水露
                    List<String> paramList2 = new ArrayList<>();
                    paramList2.add(activityInfo.getActivityName());
                    ActivityItemRecycleMgr.addRecycleItemData(config.HSISLAND_ENERGY_ITEM_ID, activityType, 1, recycleTime, paramList2);
                }
            }
        }
    }

    @Override
    protected void initActivityType() {
        activityType = eActivityType.HsIsland.getValue();
    }

    @Override
    protected void doRecycle(long userId, ActivityItemRecycleData data) {
        int type = data.getRecycleType();
        int itemId = data.getItemId();
        //获取背包道具
        UserBagItem userBagItem = getUserBagItem(userId, itemId);
        if (type == 0) {
            //深海沉银-使用掉
            if (userBagItem != null && userBagItem.getNum() > 0) {
                String activityName = data.getParamList().get(0);
                String weightReward = data.getParamList().get(1);
                Property reward = new Property();
                for (int i = 0; i < userBagItem.getNum(); i++) {
                    Property onceReward = PropertyHelper.parseNewStringToProperty(weightReward);
                    reward.addProperty(onceReward);
                }
                //删除道具，并发放奖励
                this.removeItemAndSendReward(userId, userBagItem, activityName, reward);
            }
        } else if (type == 1) {
            //望穿秋水露-直接删
            this.removeItem(userBagItem);
        }
    }

    @Override
    public boolean isActivityRunning() {
        return false;
    }
}
